from django.shortcuts import render
from django.http import HttpResponse
from rest_framework.views import APIView
from rest_framework.response import Response
from .ser import *
from .models import *
#添加用户
class add(APIView):
    def post(self,request):
        u = request.data.get('username')
        m = request.data.get('password')
        age = request.data.get('age')
        user.objects.create(username=u,password=m,age=age)
        return HttpResponse('ok')
    def get(self,request):
        #获取所有用户
        userlist = add.objects.all()
        list=[]
        #遍历对象
        for i in userlist:
            user = {}
            user['id'] = i.id
            user['username'] = i.username
            user['password'] = i.password
            user['age'] = i.age
            list.append(user)
        return Response(list)
# Create your views here.